home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / comm / uuexe515.zip / UUDECODE.DOC next >
Text File  |  1992-06-23  |  16KB  |  346 lines

  1.  
  2. Documentation for UUENCODE/DECODE 5.15
  3.  
  4. UU-encoding is a way to code a file which may contain any characters into a
  5. standard character set that can be reliably sent over diverse networks.
  6.  
  7.  
  8. THE CHARACTER ENCODING:
  9.  
  10. The basic scheme is to break groups of 3 eight bit characters (24 bits) into 4
  11. six bit characters and then add 32 (a space) to each six bit character which
  12. maps it into the readily transmittable character.  Another way of phrasing this
  13. is to say that the encoded 6 bit characters are mapped into the set:
  14.         `!"#$%&'()*+,-./012356789:;<=>?@ABC...XYZ[\]^_
  15. for transmission over communications lines.
  16.  
  17. As some transmission mechanisms compress or remove spaces, spaces are changed
  18. into back-quote characters (a 96).  (A better scheme might be to use a bias of
  19. 33 so the space is not created, but this is not done.)
  20.  
  21. Another newer less popular encoding method, called XX-encoding uses the set:
  22.         +-01..89ABC...XYZabc...xyz
  23.  
  24. In my opinion, XX-encoding is superior to UU-encoding because it uses more
  25. "normal" characters that are less likely to get corrupted.  In fact several of
  26. the special characters in the UU set do not get thru an EBCDIC to ASCII
  27. translation correctly.  Conversely, an advantage of the UU set is that it does
  28. not use lower case characters.  Now-a-days both upper and lower case are sent
  29. with no problems; maybe in the communications dark ages, there was a problem
  30. with lower case.
  31.  
  32. This "UU" encode/decode pair can handle either XX or UU encoding.  The encode
  33. program defaults to creating a UU encoded file; but can be run with a "-x"
  34. option to create an XX encoding.
  35.  
  36. The decode program defaults to autodetect.  However the program can get confused
  37. by comment lines preceeding the actual encoded data.  The decode mode can be
  38. forced to UU or XX with the "-u" or "-x" parameter.
  39.  
  40. Another option is for the character mapping table to be inserted at the front of
  41. the file.  The format for this is discussed later.  The table parameters are
  42. detected and used by this decode program.  (A table will override the "-x" or
  43. "-u" parameters.) The encode program can be run with a "-t" option which tells
  44. it to put the table into the encoded file.
  45.  
  46. A third encode mapping is the one used by Brad Templeton's ABE program.  This is
  47. not handled by these programs as the check and control information surrounding
  48. the actual encoded data is in a different form.
  49.  
  50. From a theoritical view, this encoding is breaking down 24 bits modulo 64.  Note
  51. that 64**3 is = 2**24.  The result is 24 bits in for 32 bits out, a 33% size
  52. increase.  Note that 85**5 > 2**32.  Also note that there are 94 transmittable
  53. ASCII characters (from 0x21 thru 0x7e).  Thus modulo 85 encoding (the atob
  54. encoder) transforms 32 bits to 5 ASCII chars or 40 bits for a 25% size increase.
  55.  
  56. The trade off in the module 85 encoding is that many communications systems do
  57. not reliably transmit 85 ASCII characters.  The tilda, carat, brackets, and
  58. sometimes upper or lower case frequently get corrupted.
  59.  
  60. COMPOSING A LINE OF ENCODED CHARACTERS:
  61.  
  62. A small number of eight bit characters are encoded into a single line and a
  63. count is put at the start of the line.  (Most lines in an encoded file have 45
  64. encoded characters.  When you look at a UU-encoded file note that most lines
  65. start with the letter "M".  "M" is decimal 77 which, minus the 32 bias, is 45.)
  66.  
  67. This encode program puts a check character at the end of each line.  The check
  68. is the sum of all the encoded characters, before adding the mapping, modulo 64.
  69.  
  70. Note: Horton 9/1/87 UUENCODE has a bug in the line check algorithm; it uses the
  71. sum of the original, not the encoded characters.  This decode program accepts
  72. either form of line check character.
  73.  
  74. In previous versions (4.13 and lower) the line check characters was generated by
  75. default by this encode program and was supressed with the "-L" option.  One
  76. reason to supress them is if they will be decoded by one of the old Horton
  77. decoders.  Most decoders either accept this form of check or simply stop looking
  78. after the line length is exhausted.  My feelings are mixed about the line
  79. checksums because errors of this type essentially never occur.
  80.  
  81. However with modern, error-free communications systems and with the CRC checks
  82. on the entire file (see below) I have made the default for uuencoding to have NO
  83. line level check characters effective version 4.21.  The "-L" option on uuencode
  84. turns on generation of line checksums.  If you have a really bad communications
  85. system and you want to isolate a problem, turn them on.
  86.  
  87. Uudecode automatically checks for the presense line checksums, so the default
  88. for uudecode is to leave line level checks on; if there are some problems the
  89. "-L" option for uudecode turns them off.  Sometimes there is junk at the end of
  90. the line which causes spurious line checksum errors.
  91.  
  92. I have encountered various other ways that encoders end lines.  One encoder put
  93. a "M" at both the start and end of the line.  Another used a line count
  94. character.  This decode program checks all of these.  I would not be surprised
  95. if some encoder out there ends lines with astrological symbols.  If you
  96. encounter some other wierd form of encoded file, let me know.
  97.  
  98.  
  99. PACKAGING THE LINES INTO FILES:
  100.  
  101. The lines of encoded data can be preceded by comments and by network addressing
  102. information.  The encoded data is directly preceded by a line containing:
  103.  
  104.              begin <file-mode> <file-name>
  105.  
  106. This line is created by the encoding program.  The decode program scans the file
  107. looking for "begin" in column 1.
  108.  
  109. The final end of encoded data is an encoded line with zero encoded characters (a
  110. back-quote), followed by a line containing "end".
  111.  
  112. For integrity checking, various encode programs insert checksums for the entire
  113. file.  This decode tries to check for all known types of file checksums.  This
  114. is discussed in more detail later.
  115.  
  116. This encode program puts a header line, containing the section number and file
  117. name, in front of every section:
  118.  
  119.          "section <number> of uuencode of file <file name>"
  120.  
  121. At the end of a section the encode program inserts a line containing checksum
  122. and file size information.  This can be suppressed with the "-c" option.
  123.  
  124. The transmissions on comp.binaries.ibm.pc contain two different types of section
  125. number/file-name lines.  The first is the "Archive-name line"; the other is the
  126. "part line".
  127.  
  128. The format of the Archive-name line is:
  129.         "Archive-name: <name>/part<number>"
  130. for example:
  131.         Archive-name: diskutl/part02
  132.  
  133. The format of the part line is:
  134.         <name> part<number>/<max-number>
  135. for example:
  136.         diskutl part02/03
  137.  
  138. This program checks for consistency of these names and numbers as of release
  139. 5.0.
  140.  
  141. All the "integrity fields" (the checksum, the line check, and the section header
  142. line) are inserted in a way that they will be ignored by other UUDECODE programs
  143. that cannot handle them.  This decode program does not require any of these
  144. fields; if not present, integrity checking is not done.  This program pair is
  145. 100% downward compatible!
  146.  
  147.  
  148. FILE NAMES:
  149.  
  150. The default name of the file to encode into is the base name of the file you are
  151. encoding plus the ".UUE" extension for UU encoding.
  152.  
  153.         uuencode foo.bar                produces file foo.uue.
  154.  
  155. If the -X (upper case) option is used, then the file will be XXencoded (see
  156. above); and will be saved with the default ".XXE" extension.
  157.  
  158. Uuencode can also be called with a second parameter which is the specific file
  159. name of the encoded file.  If this file name has no extension, the above default
  160. (.UUE or .XXE is used).
  161.  
  162.         uuencode    foo  foo.bar        encode foo to foo.bar
  163.         uuencode -X foo  xxfoo          encode foo to foo.xxe
  164.         uuencode -X foo  xxfoo.bar      encode foo to xxfoo.bar
  165.         uuencode    foo  xxfoo.         encode foo to xxfoo.
  166.  
  167. Uudecode defaults to look for files with the ".UUE" and the ".XXE" extension.
  168. This only applies if uudecode is called without a file name extension:
  169.  
  170.         uudecode    foo         look for file foo.uue, then foo.xxe
  171.         uudecode -u foo         look for file foo.uue only
  172.         uudecode -x foo         look for file foo.xxe, then foo.uue
  173.  
  174. If uudecode is called with a file name extension, then that is used:
  175.  
  176.         uudecode foo.XXX        decode file foo.xxx
  177.         uudecode foo.           decode file foo  with no extension
  178.  
  179.  
  180. SPLITING UP LONG FILES:
  181.  
  182. Long files are broken into several sections before transmission.  This is done
  183. because very large files are cumbersome to handle and because some networks
  184. require files to be less than 64K bytes.
  185.  
  186. This encode program automatically breaks large encoded files into sections.
  187. This split is controlled by several options.  First the "-s" option tells encode
  188. not to split the file.  The "-s nnn" option tells encode to split the file into
  189. hunks of "nnn" lines.  The default is 950 lines which is about 59k.  Sometimes
  190. extensive comments are put into the first file; thus it may be necessary for the
  191. first file to contain fewer encoded lines.  The "-h nnn" option tells encode to
  192. leave room for "nnn" additional lines in the first file.
  193.  
  194. If the data file being encoded is called FOO.ZIP, then the encode program names
  195. the encoded files FOO1.UUE, FOO2.UUE, etc.  (Or .XXE if the -X option is used.)
  196.  
  197. The decode program searches for the various sections, scans over preliminary
  198. comments and decodes all as if they were one big file.  Decode is passed the
  199. base file name "FOO".
  200.  
  201. Decode can (but rarely does) get confused and thinks header lines are encoded
  202. data.  If so, edit the file and try again.  This has only happened once to me
  203. and I have decoded a lot of files.
  204.  
  205. When decode encounters a premature end-of-file or some data which is not
  206. decodable, it assumes the end of a file section.  Decode is conservative when it
  207. encounters data it cannot decode (better an error than a bad file).
  208.  
  209. Usually this undecodable data is valid "trailer" data put at the end of file for
  210. data transmission purposes.  However the file may be bad.  So decode continues
  211. to scan the file, if decode then encounters a line which is decodable it assumes
  212. the file is bad.  Or if there are more than 30 lines remaining in the file,
  213. decode assumes the file is bad.
  214.  
  215. When decode encounters a valid end of file section it must get the next file in
  216. sequence.  If the file name ends with a number, decode tries the next file name
  217. in numeric sequence.  Otherwise decode asks for a file name.  If this file does
  218. not contain decodable data, decode asks for another file to try.
  219.  
  220. If multiple sections are saved in a single file, the sections must have one of
  221. the three (above) types of section header lines for validation.  Decode builds a
  222. table of section information so it can go back and reread if sections are not
  223. saved in order.
  224.  
  225. The "SECTION" line inserted by the UUENCODE program is used for validity
  226. checking only.  If not present, decode will accept any file containing encoded
  227. lines.
  228.  
  229.  
  230. OTHER FILE FORMS:
  231.  
  232. Sometimes files are wrapped in shell archives that automatically check
  233. sequencing and call uudecode for you on Unix systems.  If you prefer to download
  234. the raw files to MS-DOS, uudecode 5.15 will filter simple shell scripts, that
  235. use the Unix 'sed' command, and decode the data automatically.
  236.  
  237. There is one more rarely used feature of ENCODE: many input files can be encoded
  238. into one large encode file.  (I have never seen this used.) The end of an input
  239. file is a zero length encoded line, followed by another "begin" line instead of
  240. by an "end" line.  This decode program will decode this sort of file; but the
  241. encode will only handle a single input file.
  242.  
  243.  
  244. FILE LEVEL CHECKSUMS:
  245.  
  246. There are three types of file checksums found in encoded files:
  247.  
  248.        UUENCODE 2.14 and below inserted lines that gave the section
  249.        size and the original input file size.  This is supplanted
  250.        by a better technique in 3.07; but 3.07 UUDECODE still checks
  251.        and validates the old form
  252.  
  253.        UUENCODE 3.07 and Rahul Dhesi''s encode scripts compute a Unix
  254.        "sum -r" on the encoded sections and on the original input file.
  255.        A difference is that UUENCODE 3.07 puts the expected "sum -r"
  256.        and size at the end of a file while Rahul''s scripts put them at
  257.        begining.  This UUDECODE analyzes either.
  258.  
  259.        The third form of checksum is a full 32 bit CRC that Rahul's script
  260.        inserts.  My code does not handle this.  Rahul has written the
  261.        BRIK program to check them.  If there is a "sum -r" failure, BRIK
  262.        analysis should be considered.
  263.  
  264. Unisys Unix platforms put a line containing just the original file size at the
  265. end of the encoded file.  My code checks this.
  266.  
  267.  
  268. TABLE LINES:
  269.  
  270. Some encoded files but the mapping used at the front of the encoded file, just
  271. in front of the "begin" line.  The format for this is:
  272.  
  273.                    table
  274.                    first 32 characters
  275.                    second 32 characters
  276.  
  277. All this starts in column 1.
  278.  
  279. If decode encounters a table specification, it uses it and overrides any command
  280. line parameters.  Encode will create the table lines if run with the "-t"
  281. parameter.
  282.  
  283.  
  284. COMPLETION CODES:
  285.  
  286. On successful completion, UUDECODE sets ERRORLEVEL to 0.  If there are any
  287. problems, ERRORLEVEL is set to non-zero.
  288.  
  289. Most of the options to UUDECODE are obvious.  However, the "-e" option needs
  290. more explanation.  The purpose of "-e" is to automatically run an un-archiver
  291. (like ZOO or PKUNPAK) when UUDECODE successfully completes.  If the "-e" option
  292. is given, UUDECODE calls BAT file UNARCUUE on successful completion UNARCUUE is
  293. passed two parameters:
  294.  
  295.                 the filename decoded (with no extension)
  296.                 the file extension.
  297.  
  298. Normally the file extension tells which un-archiver to call.  The UNARCUUE BAT
  299. file, can test these parameters and call the necessary un-archiver.
  300.  
  301.  
  302. This works well for me.  On UNIX I find a program I want in three sections:
  303.               PRG1, PRG2, PRG3.
  304. I copy the three files down to my PC as PRG1.UUE, PRG2.UUE, and PRG3.UUE.  I
  305. then just enter UUDECODE PRG and the thing decodes.
  306.  
  307.  
  308. Done privately and not for profit (freeware).  Suggestions appreciated.
  309. The programs are written in Turbo Pascal 5.5 with about 5% TASM for speed.  The
  310. source is not public domain.  I would entertain consulting contracts for porting
  311. to other hardware platforms.  Also if included in your for profit product,
  312. please contact me.
  313.  
  314.  
  315. Richard Marks
  316. 931 Sulgrave Lane
  317. Bryn Mawr, PA 19010
  318.  
  319. Copyright Richard E. Marks, Bryn Mawr, PA, 1992
  320.  
  321. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  322.  
  323. Change log (started with 5.13):
  324. 5.15
  325. 5.15 fixes a problem with trailing blanks on lines.
  326.  
  327. 5.14:
  328.  
  329. 5.14 fixes a minor bug in which a redundant error message was produced
  330. when decoding single section files.
  331.  
  332.  
  333. 5.13 VERSUS 5.10:
  334.  
  335. 5.13 decode has a command line option that disables all interactive
  336. responses to make it more useable from some BBS systems.  Examine the
  337. "y" and "Y" options.
  338.  
  339. 5.13 can increment the number on files up to five digits.  The prior
  340. limit was two digits.  You can now save files with names based on news
  341. article numbers.
  342.  
  343. 5.13 can decode files encoded into 100 or more parts.  A restriction is
  344. that if there are more than 100 parts, the sections MUST be in order.
  345.  
  346.